<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Home</title>
    <link rel="stylesheet" type="text/css" href="__STATIC__/plugins/layui/css/layui.css">
    <script type="text/javascript" src="__STATIC__/plugins/layui/layui.js"></script>

    <style type="text/css">
        .header span{background: #009688;margin-left: 30px;padding: 10px;color: #ffffff;}
        .header div{border-bottom: solid 2px #009688;margin-top: 8px;}
        .header button{float: right;margin-top: -5px;}
    </style>
</head>
<body style="padding: 10px;">
    <div class="header">
        <span>首页首屏</span>
        <button class="layui-btn layui-btn-sm" onclick="add()">添加</button>
        <div></div>
    </div>
    <!--<form class="layui-form">-->
    <table class="layui-table">
        <thead>
            <tr>
                <th>ID</th>
                <th>排序</th>
                <th>标题</th>
                <th>URL</th>
                <th>图片</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {volist name="data" id='vo'}
            <tr>
                <td>{$vo.id}</td>
                <td>{$vo.ord}</td>
                <td>{$vo.title}</td>
                <td>{$vo.url}</td>
                <td><img src="{$vo.img}" style="height: 30px;"></td>
                <td>
                    <button class="layui-btn layui-btn-xs" onclick="add({$vo.id});return false">编辑</button>
                    <button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({$vo.id})">删除</button>
                </td>
            </tr>
            {/volist}
        </tbody>
    </table>
    <!--</form>-->
    <script type="text/javascript">
        layui.use(['layer','form'],function(){
            $ = layui.jquery;
            layer = layui.layer;
            // form = layui.form;
        });

        // 添加或编辑（添加则不传入id  编辑则传入id）
        function add(id) {
            layer.open({
                type: 2,
                title: id>0?'编辑幻灯片':'添加幻灯片',
                shade: 0.3,
                area: ['480px', '420px'],
                content: "{:url('admins/Slide/add_first')}?id="+id
            });
        }

        // 删除
        function del(id) {
            //询问框
            layer.confirm('确定要删除么？', {
                icon:3,
                btn: ['确定','取消'] //按钮
            }, function(){
                $.post("{:url('admins/Slide/delete')}",{'id':id},function (res) {
                    // var res = JSON.parse(res);  //字符串转json对象
                    if(res.code){
                        layer.alert(res.msg,{ico:2});                           // 显示后台返回的数据
                    }else{
                        layer.msg(res.msg,{icon:1});                            // 显示后台返回的数据
                        setTimeout(function(){window.location.reload();},500);  // 返回本页面
                    }
                },'json');
            });
        }
    </script>
</body>
</html>
